package com.gzx.plugin.data.wckj.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.gzx.plugin.data.wckj.entity.DataWckjYwyhid;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface DataWckjYwyhidMapper extends BaseMapper<DataWckjYwyhid> {

    @Insert("<script> " +
            "INSERT INTO data_wckj_ywyhid " +
            "(ywyh_id, status, case_batch, create_time, update_time) " +
            "VALUES" +
            "<foreach collection='wckjYwyhIdList' item='user' separator=','>" +
            "(" +
            "#{user.ywyhId}," +
            "'0'," +
            "#{user.caseBatch}," +
            "now()," +
            "now()" +
            ")" +
            "</foreach>" +
            "</script>")
    void insertBatch(@Param("wckjYwyhIdList") List<DataWckjYwyhid> wckjYwyhIdList);

    @Select("select ywyh_id FROM data_wckj_ywyhid where status = '0' and  case_batch = 'M4+' limit 5")
    List<String> getDataListM4Top5();

    @Select("select ywyh_id FROM data_wckj_ywyhid where status = '0' and  case_batch = 'M7+' limit 5")
    List<String> getDataListM7Top5();

    @Select("select ywyh_id FROM data_wckj_ywyhid where status = '0' and  case_batch = 'M12+' limit 5")
    List<String> getDataListM12Top5();


    @Update("<script>" +
            "UPDATE data_wckj_ywyhid " +
            "SET status = '1' " +
            "WHERE ywyh_id IN " +
            "<foreach collection='list' item='uid' open='(' separator=',' close=')'>" +
            "   #{uid}" +
            "</foreach>" +
            "</script>")
    void updateDataBatch(@Param("list") List<String> list);

    @Select("<script>" +
            "select count(1) from data_wckj_ywyhid where create_time > #{currentMonth} and status = 0 " +
            "<if test='projectCode != null and projectCode != \"\"'>AND case_batch = #{projectCode} </if>" +
            "</script>")
    int getStatusCount(String currentMonth, String projectCode);
}
